/*
 * @Author: zhangwei 1405298045@qq.com
 * @Date: 2022-03-11 10:09:40
 * @LastEditTime: 2022-04-21 10:27:40
 * @LastEditors: zhangwei 1405298045@qq.com
 * @Description:
 * @FilePath: /ll-fe-mp-dyfx/src/store/modules/temporary.js
 *
 */
import currency from 'currency.js';
import { getSystemInfo } from '@/utils';

export default {
	state: {
		featuredWorks: {},
		merchantStore: [],

		coordinate: {},
		tandianProductDetail: {}
	},

	getters: {
		coordinate({ coordinate }) {
			return coordinate;
		},

		featuredWorks({ featuredWorks }) {
			return featuredWorks;
		},

		merchantStore({ merchantStore }) {
			return merchantStore;
		},

		tandianProductDetail({ tandianProductDetail }) {
			return tandianProductDetail;
		}
	},

	mutations: {
		changeCoordinate(state, params) {
			state.coordinate = params;
		},

		changeFeaturedWorks(state, params = {}) {
			const { list, total = 0 } = params;

			const { screenHeight } = getSystemInfo();

			const formatList = (list || []).map((item, index) => {
				const [width, height] = (item.pixel || '').split('*');
				const formatMoney = currency(item.money / 100, { symbol: '', precision: 0 }).format();

				return Object.assign(
					{
						...item,

						index,
						formatMoney
					},

					height && { height: `${Math.min(height, screenHeight)}px` }
				);
			});
			state.featuredWorks = {
				total,
				list: formatList
			};
		},

		changeMerchantStore(state, params) {
			state.merchantStore = params;
		},

		changeTandianProductDetail(state, params) {
			state.tandianProductDetail = params;
		}
	}
};
